# Report test coverage to coveralls.io.
require 'coveralls'
Coveralls.wear!

# Set the environment to test.
ENV['RACK_ENV'] = 'test'

require 'pyro/cli'
require 'pyro/app'

require 'minitest'
require 'minitest/autorun'
require 'minitest/pride'
require 'rack/test'

# Public: Sets up the test environment.
#
# Example
#
#   ~/pyro $ rake test
class TestPyro < Minitest::Test
  include Rack::Test::Methods

  # Set the name of the Sinatra app to test.
  def app
    Pyro::App
  end

  # Creates and bootstraps a test Pyro app in /tmp/test.
  def setup
    Pyro::CLI.new.create('tmp/test') unless Dir.exists? 'tmp/test'
    app.set :environment, :test
    app.set :root, 'tmp/test'
    app.set :public_folder, 'tmp/test/public'
    app.set :links, []
    app.set :timestamp, Time.now.strftime('%Y%m%d%H%M%S')
    @helpers = app.new.helpers
  end
end

# Removes the test Pyro app after all the tests have run.
Minitest.after_run do
  FileUtils.rm_rf './tmp'
end